import Vue from 'vue'
import {
  Toast,
  Swipe,
  SwipeItem
} from 'vant';
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'

Vue.config.productionTip = false
Vue.prototype.$axios = axios

Vue.use(Toast)
Vue.use(Swipe)
Vue.use(SwipeItem)

let toastLoading = null
// 请求/响应 拦截器
axios.interceptors.request.use(config => {
  toastLoading = Toast.loading({
    duration: 0, // 持续展示
    message: '加载中...',
    forbidClick: true,
  })
  return config
}, err => {
  return Promise.reject(err)
})

axios.interceptors.response.use(response => {
  toastLoading.clear()
  return response
}, err => {
  toastLoading.message = '网络错误，稍后重试'
  setTimeout(() => toastLoading.clear(), 800)
  return Promise.reject(err)
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')